import React from 'react'
import { useLocation, useParams, } from '../react-router-dom'
import { UserAPI } from '../utils'

function UserDetail() {
  let [user, setUser] = React.useState({})
  let params = useParams()
  // console.log(params, 'userDetail params')
  let location = useLocation() // 获取位置对象
  React.useEffect(() => {
    let user = location.state // 获取状态
    window.a = location
    // console.log('location.state ', location.state)
    if(!user) {
      // console.log(UserAPI.find(params.id), 'UserAPI.find(params.id)')
      user = UserAPI.find(params.id)
    }
    if(user) {
      setUser(user)
    }
  }, [])
  return <div>
    <p>ID： {user.id}</p>
    <p>Name： {user.name}</p>
  </div>
}

export default UserDetail
